/*
 * @Author: 李环玉 834654733@qq.com
 * @Date: 2023-11-25 19:03:33
 * @LastEditors: 李环玉 834654733@qq.com
 * @LastEditTime: 2024-01-07 05:01:12
 * @FilePath: \koa-server\src\app\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const Koa = require('koa')
const path = require('path')
const { koaBody } = require('koa-body')
const parameter = require('koa-parameter')
const koaStatic = require('koa-static')
const cors = require('koa2-cors');// CORS是一个W3C标准，全称是"跨域资源共享"
const router = require('../router/index')
const app = new Koa()
app.use(koaBody({
  multipart:true,
  formidable:{
    uploadDir:path.join(__dirname,'../../../blog-system/dist/upload'),
    keepExtensions:true
  }
}))
app.use(koaStatic(path.join(__dirname,'../upload')))
app.use(parameter(app))
app.use(cors()); //全部允许跨域
app.use(router.routes())
// // 统一的错误处理
// app.on('error', errHandler)
app.use(router.allowedMethods())
app.use(cors)
module.exports = app